package main

import (
	"fmt"
	"time"
)

func main() {
	channel := make(chan int)

	for i := 0; i < 3; i++ {
		go example(channel, i)
	}
	time.Sleep(2 * time.Second)
	close(channel)
	time.Sleep(5 * time.Second)
	fmt.Println("主程序退出!")
}

func example(ch chan int, i int) {
	for {
		select {
		case d := <-ch:
			fmt.Printf("监控器%v,接收到的值为: %v,监控结束。\n", i, d)
			return
		default:
			fmt.Printf("监控器%v，正在监控中...\n", i)
			time.Sleep(2 * time.Second)
		}
	}
}
